<?php
/*********************************************************************************
 * Copyright (C) 2011-2013 X2Engine Inc. All Rights Reserved.
 *
 * X2Engine Inc.
 * P.O. Box 66752
 * Scotts Valley, California 95067 USA
 *
 * Company website: http://www.x2engine.com
 * Community and support website: http://www.x2community.com
 *
 * X2Engine Inc. grants you a perpetual, non-exclusive, non-transferable license
 * to install and use this Software for your internal business purposes.
 * You shall not modify, distribute, license or sublicense the Software.
 * Title, ownership, and all intellectual property rights in the Software belong
 * exclusively to X2Engine.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT.
 ********************************************************************************/

/* @edition:pro */

$this->pageTitle = Yii::t('marketing','Web Lead Form');
$this->actionMenu = $this->formatMenu(array(
	array('label'=>Yii::t('marketing','All Campaigns'), 'url'=>array('index')),
	array('label'=>Yii::t('marketing','Create Campaign'), 'url'=>array('create')),
	array('label'=>Yii::t('contacts','Contact Lists'),'url'=>array('/contacts/lists')),
	array('label'=>Yii::t('marketing','Newsletters'),'url'=>array('weblist/index')),
	array('label'=>Yii::t('marketing','Web Lead Form'), 'url'=>array('webleadForm')),
	array('label'=>Yii::t('marketing','Web Tracker')),
	array('label'=>Yii::t('app','X2Flow'),'url'=>array('/studio/flowIndex'))
));


$timeLengths = array(
	1=>Yii::t('app','{n} sec',1),
	5=>Yii::t('app','{n} sec',5),
	15=>Yii::t('app','{n} sec',15),
	30=>Yii::t('app','{n} sec',30),
	60=>Yii::t('app','{n} min',1),
	300=>Yii::t('app','{n} min',5),
	900=>Yii::t('app','{n} min',15),
	1800=>Yii::t('app','{n} min',30),
	3600=>Yii::t('app','{n} hour',1),
	7200=>Yii::t('app','{n} hours',2),
	28800=>Yii::t('app','{n} hours',8),
	86400=>Yii::t('app','{n} day',1),
);
// 1-based indeces
$cooldownIndex = array_search($admin->webTrackerCooldown,array_keys($timeLengths));
if($cooldownIndex === false)
	$cooldownIndex = count($timeLengths);	// default to last value (unlimited)
else
	$cooldownIndex++;


Yii::app()->clientScript->registerScript('updateCooldownSlider','

$("#cooldown, #enableTracker").change(function(){ $("#save-button").addClass("highlight"); });

$("#cooldown").change(function(){ $("#cooldownSlider").slider("value",$(this).prop("selectedIndex")+1); });
',CClientScript::POS_READY);


?>
<div class="page-title icon marketing">
	<h2><?php echo Yii::t('marketing','Web Tracker Code'); ?></h2>
</div>
<div class="form">
<h4><?php echo Yii::t('marketing','Web Tracker Code') .':'; ?></h4>
<?php echo Yii::t('marketing','This HTML tag will allow you to track contacts who visit your website.'); ?><br>
<?php echo Yii::t('marketing','Paste this code into the body section of every page of your website.'); ?><br>

<textarea id="embedcode" style="background:#eee"><iframe src="<?php echo Yii::app()->request->getHostInfo(),Yii::app()->getBaseUrl(); ?>/webListener.php" height="0" width="0"></iframe></textarea>
<?php //echo Yii::t('marketing','Copy and paste this code into your website to include the web lead form.'); ?><br>

<?php echo Yii::t('marketing','<b>Note:</b> Contacts can be tracked only if they filled out the web lead capture form, or clicked on a tracking link in an email campaign.'); ?><br><br>

<?php echo CHtml::beginForm(); ?>
<h4><b><?php echo Yii::t('marketing','Web Tracker Settings'); ?></b></h4>
<div class="row">
	<?php echo Yii::t('marketing','You can enable or disable the web tracker. The tracker will ignore repeat hits from a given contact during the cooldown period.'); ?>
	<?php echo Yii::t('marketing','If a contact visits several pages in a short time, you will only get one notification.'); ?>
	<?php echo Yii::t('marketing','Turn it down all the way to receive notifications about every page hit.'); ?>
</div><br>
<div class="row">
	<div class="cell" style="width:120px;">
		<?php echo CHtml::activeLabel($admin,'enableWebTracker'); ?>
		<?php echo CHtml::activeDropDownList($admin,'enableWebTracker',array(1=>Yii::t('app','Enable'),0=>Yii::t('app','Disable')),array('id'=>'enableTracker','style'=>'')); ?>
	</div>
	<div class="cell" style="width:450px;">
		<?php echo CHtml::activeLabel($admin,'webTrackerCooldown'); ?>
		<?php echo CHtml::activeDropDownList($admin,'webTrackerCooldown',$timeLengths,array('id'=>'cooldown','style'=>'float:left;')); ?>
		<?php
		$this->widget('zii.widgets.jui.CJuiSlider', array(
			'value' => $cooldownIndex,
			// additional javascript options for the slider plugin
			'options' => array(
				'min'=>1,
				'max'=>count($timeLengths),
				'slide'=>'js:function(event,ui) {
					$("#save-button").addClass("highlight");
					$("#cooldown>option:nth-child("+ui.value+")").attr("selected",true);
				}',
			),
			'htmlOptions' => array(
			'style' => 'width:300px;margin:10px;display:inline-block;',
			'id' => 'cooldownSlider'
			),
		));
		?>
	</div>
</div>


<?php echo CHtml::submitButton(Yii::t('app','Save'),array('class'=>'x2-button btn btn-mini  btn-yellow left','id'=>'save-button','style'=>'')); ?>
<?php echo CHtml::endForm(); ?>



</div>
